package 华为OD机试真题2023.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class HJ24_字母组合 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/24.txt"));
        MyUtil.START();
        Solution(in);
        //        Solution2(in);
        MyUtil.END();
    }

    static char[][] index = {
        {'a', 'b', 'c'},
        {'d', 'e', 'f'},
        {'g', 'h', 'i'},
        {'j', 'k', 'l'},
        {'m', 'n', 'o'},
        {'p', 'q', 'r'},
        {'s', 't'},
        {'u', 'v'},
        {'w', 'x'},
        {'y', 'z'}
    };

    static void Solution(Scanner in) {
        String str1 = in.nextLine();
        String Exclude = in.nextLine();
        char[] first = index[str1.charAt(0) - '0'];
        List<String> arr = new ArrayList<>();
        for (int i = 0; i < first.length; i++) {
            arr.add(String.valueOf(first[i]));
        }
        for (int i = 1; i < str1.length(); i++) {
            char[] add = index[str1.charAt(i) - '0'];
            arr = handle(arr, add);
        }
        StringBuilder result = new StringBuilder();
        for (String tmp : arr) {
            if (!tmp.contains(Exclude)) {
                result.append(tmp).append(",");
            }
        }
        System.out.println(result);
    }

    static List<String> handle(List<String> arr, char[] add) {
        List<String> result = new ArrayList<>();
        for (int i = 0; i < arr.size(); i++) {
            for (int j = 0; j < add.length; j++) {
                result.add(arr.get(i) + add[j]);
            }
        }
        return result;
    }

    static void Solution2(Scanner sc) {
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        List<String[]> list = initList();
        List<String[]> indexList = new ArrayList<>();
        int n = str1.length();
        for (int i = 0; i < n; i++) {
            int index = Integer.parseInt(str1.substring(i, i + 1));
            indexList.add(list.get(index));
        }
        List<String> arr = Arrays.asList(indexList.get(0));
        for (int i = 1; i < indexList.size(); i++) {
            arr = build(arr, indexList.get(i));
        }

        for (String str : arr) {
            if (check(str, str2)) {
                System.out.print(str + ",");
            }
        }
    }

    static boolean check(String str, String checkStr) {
        for (int i = 0; i < checkStr.length(); i++) {
            if (!str.contains(checkStr.substring(i, i + 1))) {
                return true;
            }
        }
        return false;
    }

    static List<String> build(List<String> str, String[] arr) {
        List<String> result = new ArrayList<>();
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < arr.length; j++) {
                result.add(str.get(i) + arr[j]);
            }
        }
        return result;
    }

    static List<String[]> initList() {
        List<String[]> list = new ArrayList<>();
        list.add(new String[] {"a", "b", "c"});
        list.add(new String[] {"d", "e", "f"});
        list.add(new String[] {"g", "h", "i"});
        list.add(new String[] {"j", "k", "l"});
        list.add(new String[] {"m", "n", "o"});
        list.add(new String[] {"p", "q", "r"});
        list.add(new String[] {"s", "t"});
        list.add(new String[] {"u", "v"});
        list.add(new String[] {"w", "x"});
        list.add(new String[] {"y", "z"});
        return list;
    }
}
